﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WorkRecorder.Data;
using System.IO;
using System.Collections.ObjectModel;

namespace WorkRecorder.Business
{
    public class RecordManager
    { 

        public ObservableCollection<Record> GetRecords(string dataPath)
        {
            try
            {
                IDataMapper<Records<Record>> dm = new DataMapperXmlImpl();
                Records<Record> recordSet = dm.ReadGraph(dataPath);
                return recordSet.RecordSet;
            }
            catch (FileNotFoundException e)
            {

                return null;
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        public void SaveRecords(ObservableCollection<Record> graph, string dataPath)
        {
            try
            {
                DataMapperXmlImpl dm = new DataMapperXmlImpl();                
                Records<Record> r = new Records<Record>();
                r.RecordSet = graph;
                dm.SaveGraph(r, dataPath);
            }
            catch (Exception e)
            {
                throw e;
            }
        }

        public ObservableCollection<Record> CloneSet(ObservableCollection<Record> set)
        {
            Records<Record> tmpR = new Records<Record>();
            tmpR.RecordSet = set;
            ObservableCollection<Record> tempSet = tmpR.Clone() as ObservableCollection<Record>;
            return tempSet;
        }
    }
}
